package org.kabeja.parser.table;

import org.kabeja.dxf.DXFConstants;
import org.kabeja.dxf.entity.DXFLayer;
import org.kabeja.parser.DXFValue;

/**
 * @author shutao
 * @since 2022/4/25 14:14
 */
public class DXFLayerTableHandler extends AbstractTableHandler {
    public static final int GROUPCODE_LAYER_NAME = 2;
    public static final int GROUPCODE_LAYER_LINETYPE = 6;
    public static final int GROUPCODE_LAYER_COLORNUMBER = 62;
    public static final int GROUPCODE_LAYER_PLOTTINGFLAG = 70;
    public static final int GROUPCODE_LAYER_LINEWEIGHT = 370;
    public static final int GROUPCODE_LAYER_PLOTSTYLENAME = 390;
    private DXFLayer layer;

    public DXFLayerTableHandler() {
    }

    @Override
    public String getTableKey() {
        return DXFConstants.TABLE_KEY_LAYER;
    }

    @Override
    public void parseGroup(int var1, DXFValue var2) {
        switch(var1) {
            case GROUPCODE_LAYER_NAME:
                this.layer.setName(var2.getValue());
                break;
            case GROUPCODE_LAYER_LINETYPE:
                this.layer.setLineType(var2.getValue());
                break;
            case GROUPCODE_LAYER_COLORNUMBER:
                this.layer.setColor(var2.getIntegerValue());
                break;
            case GROUPCODE_LAYER_PLOTTINGFLAG:
                this.layer.setFlags(var2.getIntegerValue());
                break;
            case GROUPCODE_LAYER_LINEWEIGHT:
                this.layer.setLineWeight(var2.getIntegerValue());
                break;
            case GROUPCODE_LAYER_PLOTSTYLENAME:
                this.layer.setPlotStyle(var2.getValue());
                break;
            default:
                break;
        }
    }

    @Override
    public void endParsing() {
        this.doc.addDXFLayer(this.layer);
    }

    @Override
    public void startParsing() {
        this.layer = new DXFLayer();
        this.layer.setDXFDocument(this.doc);
    }
}